/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Operaciones;

import ClasesTablas.Libro;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author CHENTEHC
 */
public class AgregarLibro {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         Session session = null;
        try{
                Configuration configuration=new Configuration();
                SessionFactory sessionFactory=configuration.configure().buildSessionFactory();
                session=sessionFactory.openSession();
                Transaction transaction=session.beginTransaction();

                System.out.println("Añadiendo un nuevo libro");
                Libro lib= new Libro();
                lib.setTitulo("Codigo");
                lib.setAutor("Dan Brown");
                
                

                session.save(lib);
                session.getTransaction().commit();

                System.out.println("Listo");
        }catch(Exception e){
            System.out.println(e.getMessage());
        } 
        finally{
            session.flush();
            session.close();
        }
        
        
    }

    }
    

